﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LeetcodeTest._100._40
{
    public class Leetcode33
    {
        /*
         33. Search in Rotated Sorted Array 

        Suppose a sorted array is rotated at some pivot unknown to you beforehand.

(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).

You are given a target value to search. If found in the array return its index, otherwise return -1.

You may assume no duplicate exists in the array.

         */

            /// <summary>
            /// 这太简单了把。。。还是hard的难度
            /// 是我打开的方式不对。。还是题目有限制不能使用list。。
            /// </summary>
            /// <param name="nums"></param>
            /// <param name="target"></param>
            /// <returns></returns>
        public int Search(int[] nums, int target)
        {
            int iRet = -1;
            List<int> listNums = new List<int>(nums);
            if (!listNums.Contains(target))
                return iRet;
            else
                iRet = listNums.IndexOf(target);

            listNums.CopyTo(0, nums, nums.Length - iRet, iRet);
            listNums.CopyTo(iRet, nums, 0, nums.Length - iRet);

            return iRet;
        }
    }
}
